package com.hmf.service;

import com.hmf.bean.*;
import com.hmf.dao.HmfMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HmfMenuServiceImpl implements HmfMenuService{
    @Autowired
    HmfMenuMapper hmfMenuMapper;


    public List<Control> queryMenuByRole(int role_id){
        List<Control> control = hmfMenuMapper.queryMenuByRole(role_id);
        return control;
    }
    //用户骑行记录
    public List<RideRecord> searchRideRecord(String username){
        List<RideRecord> rideRecord=hmfMenuMapper.searchRideRecord(username);
        return rideRecord;
    }

    //查询单车状态
    public List<Bicycle> searchRideStatus(){
        List<Bicycle> bicycle=hmfMenuMapper.searchRideStatus();
        return bicycle;
    }

    //故障单车登记
    public int insertRideRepair(RideRepair rideRepair) {
        int r = hmfMenuMapper.insertRideRepair(rideRepair);
        System.out.println(r + "插入数据");
        if (r == 1) {
            System.out.println("单车故障登记成功.");
            return 0;
        } else {
            System.out.println("单车故障登记失败.");
            return 2; // 插入失败
        }
    }

    //所有用户骑行记录
    public List<RideRecord> searchAllRideRecord(){
        List<RideRecord> rideRecord=hmfMenuMapper.searchAllRideRecord();
        return rideRecord;
    }

    //故障单车处理
    public List<RideRepair> rideRepair(){
        List<RideRepair> rideRepair=hmfMenuMapper.rideRepair();
        return rideRepair;
    }

    //故障单车更新
    public int updateRepair(int repairID){
        int r= hmfMenuMapper.updateRepair(repairID);
        if (r == 1) {
            return 0;//更新成功
        } else {
            return 2;//更新失败
        }
    }

}
